define([
    'underscore',
    'backbone'
], function(_, Backbone) {

    var OperatorModel = Backbone.Model.extend({
        urlRoot: 'server/api/operator',
        initialize: function() {

        },
        validate: function(attributes) {
            var errors = {};
            if (!attributes.name) {
                errors.name = ["Razón Social no debe ser vacio"];
            }
            if (!attributes.code) {
                errors.code = ["RUC no debe ser vacio"];
            } else {
                if (!/^\d+$/.test(attributes.code)) {
                    errors.code = ["RUC debe tener solo digitos "];
                } else {
                    if (attributes.code.length != 11) {
                        errors.code = ["RUC debe tener  11 de longitud"];
                    }
                }
            }
            if (!attributes.address) {
                errors.address = ["Direccíon no debe ser vacio"];
            }
            return _.isEmpty(errors) ? undefined : errors;
        }
    });
    return OperatorModel;
});
